﻿namespace WebPacker.Tool.Tests.EqualityComparers
{
	using System;
	using System.Collections.Generic;
	using NUnit.Framework;
	using WebPacker.Filters;

	public class FilterEqualityComparer : IEqualityComparer<IFilter>
	{
		public bool Equals(IFilter x, IFilter y)
		{
			if (x == null || y == null)
			{
				return false;
			}

			if (x.Name != y.Name)
			{
				return false;
			}

			Assert.AreEqual(x.PackType, y.PackType);
			Assert.AreEqual(x.GetType(), y.GetType());

			if (x is YuiCssMinifier)
			{
				var a = (YuiCssMinifier)x;
				var b = (YuiCssMinifier)y;

				Assert.AreEqual(a.ColumnWidth, b.ColumnWidth);
				Assert.AreEqual(a.CompressionType, b.CompressionType);
			}
			else if (y is YuiJavascriptMinifier)
			{
				var a = (YuiJavascriptMinifier)x;
				var b = (YuiJavascriptMinifier)y;

				Assert.AreEqual(a.DisableOptimizations, b.DisableOptimizations);
				Assert.AreEqual(a.IsObfuscateJavascript, b.IsObfuscateJavascript);
				Assert.AreEqual(a.LineBreakPosition, b.LineBreakPosition);
				Assert.AreEqual(a.PreserveAllSemicolons, b.PreserveAllSemicolons);
			}

			return true;
		}

		public int GetHashCode(IFilter obj)
		{
			throw new NotImplementedException();
		}
	}
}
